'''
Company: TWL
Author: xue jian
Email: xuejian@kanzhun.com
Date: 2020-10-29 19:54:02
'''
#
# @lc app=leetcode.cn id=452 lang=python3
#
# [452] 用最少数量的箭引爆气球
#

# @lc code=start
from typing import List
class Solution:
    def findMinArrowShots(self, points: List[List[int]]) -> int:
        if not points:
            return 0
        points.sort(key = lambda x:x[1])
        ans = 1

        # print(points)
        end = points[0][1]
        for p in points[1:]:
            if p[0]>end:
                ans+=1
                end = p[1]
        return ans

        # print(points)
# @lc code=end

if __name__ == "__main__":
    solution = Solution()
    points = [[0,9],[1,8],[7,8],[1,6],[9,16],[7,13],[7,10],[6,11],[6,9],[9,13]]
    print(solution.findMinArrowShots(points))
    import matplotlib.pyplot as plt
    import numpy as np
    # y = np.array([1, 1])
    for i, p in enumerate(points):
        y = [i, i]
        plt.plot(p, y)
    plt.show()